
<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>新增地址</title>
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<!-- 引入样式 -->
		<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/vant@1.6/lib/index.css">		
		<!-- 引入组件 -->
		<script src="../../js/vue.min.js"></script>
		<script src="../../js/vant.min.js"></script>
		<script src="html5plus://ready"></script>
		<script src="../../js/ajax.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/area.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../js/listener_other.js" type="text/javascript" charset="utf-8"></script>
	<style type="text/css">
			body {
				background-color: #E5E5E5;
			}
			#app {
				margin-top: 46px;
			}
		</style>
	</head>
	<body>
		<div id="app">
			<header>
				<van-nav-bar @click-left="onClickLeft" style="background-color: red;">
					<van-icon slot="left" name="arrow-left" color="white"></van-icon>
					<label slot="title" class="white">新增收货地址</label>
				</van-nav-bar>
			</header>
			<van-address-edit :area-list="areaList" show-set-default @save="onSave"></van-address-edit>
		</div>
	</body>
	<script type="text/javascript">
		var newUser = localStorage.getItem("user"); //从localStorage里取数据(字符串格式)
		newUser = JSON.parse(newUser); //把字符串格式转换成Json格式
		var vm = new Vue({
			el: "#app",
			data: {
				areaList: address,//地址数组
			},
			methods: {
				onSave: function(addressInfo) {//保存
					var _this = this;
					console.log(newUser);
					var s=addressInfo.areaCode;
					var a=localStorage.setItem("code",s);//把六位数的地址信息存到localstorage里
					ajax({
						url: "http://dsapi.ysd3g.com/API/AddShippingAddress",
						dataType: "jsonp",
						data: {
							key: newUser.Key, //登陆返回的Key
							name:addressInfo.name,//收货人名称
							phone:addressInfo.tel,//收货人手机号码
							districtCode:addressInfo.areaCode,//收货人区县code
							address:addressInfo.addressDetail,//收货人详细地址
							isdefault:addressInfo.isdefault//是否为默认地址
						},
						success: function(res) {
							if(res.Error){
								_this.$toast.alert("出现错误，请稍后再试！")
							}else{
								plus.webview.close(plus.webview.currentWebview(),"slide-out-left");
								var shouhuo=plus.webview.getWebviewById("shdz");
								shouhuo.reload(true);
							}
						}
					});
				},
				onClickLeft:function(){//返回
					plus.webview.close(plus.webview.currentWebview(),"slide-out-left");
				}
			}
		})
	</script>
</html>